package com.choudou5.solr.framework.constants;

import com.choudou5.solr.util.ConfigUtil;
import com.choudou5.solr.util.StrUtil;

/**
 * @name 用户常量
 * @author choudou5
 * @date 2018-7-16
 */
public interface UserConsts {

    String USER_BEAN_SESSION_KEY = "user_bean_session_key";

    int MAX_ONLINE = ConfigUtil.getInt("user.online.max");

    Integer SYS_USER_ID = -999;

    enum UserStatus {

        DISABLE("0", "禁用"),
        NORMAL("1", "正常"),
        OUT("2", "离职"),
        ;

        UserStatus(String key, String desc) {
            this.key = key;
            this.desc = desc;
        }

        private String key;
        private String desc;

        public boolean eq(String key){
            if(StrUtil.isBlank(key))
                return false;
            return getKey().equals(key);
        }

        public static UserStatus get(String key){
            UserStatus[] values = values();
            for (UserStatus status : values) {
                if(status.getKey().equals(key)) {
                    return status;
                }
            }
            return null;
        }

        public String getKey() {
            return key;
        }
        public String getDesc() {
            return desc;
        }
    }

    enum UserRole {
        NORMAL("0", "普通"),
        ADMIN("1", "管理员"),
        SUPER_ADMIN("2", "超级管理员"),
        ;

        UserRole(String key, String desc) {
            this.key = key;
            this.desc = desc;
        }

        private String key;
        private String desc;

        public boolean eq(String key){
            if(StrUtil.isBlank(key))
                return false;
            return getKey().equals(key);
        }
        public String getKey() {
            return key;
        }
        public String getDesc() {
            return desc;
        }
    }


}
